<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5                                                          |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License,        |
// | that is available at http://www.php.net/license/3_0.txt.               |
// | If you did not receive a copy of the PHP license and are unable to     |
// | obtain it through the world-wide-web, please send a note to            |
// | license@php.net so we can mail you a copy immediately.                 |
// +------------------------------------------------------------------------+
// | Author:                                                                |
// +------------------------------------------------------------------------+
//
// $Id: Db.php 54 2008-07-13 06:12:18Z garfield0601 $
//
require_once("SmartPHP/Db/Exception.php");

/**
* @author       vv
*/
class SmartPHP_Db
{
	/**
	 * _config 
	 * 
	 * @var array
	 * @access private
	 */
	private static $_config;
	/**
	 * _dsn 
	 * 
	 * @var string
	 * @access private
	 */
	private static $_dsn;
	/**
    /**
     * factory 
     * 
     * @param array $dbConfig 
     * @static
     * @access public
     * @return object
     */
    public static function factory($dbConfig)
    {
		self::$_config = $dbConfig;
		self::$_dsn    = self::_setDSN();
		try{
			$connection = new PDO(self::$_dsn , 
				self::$_config['username'] , 
				self::$_config['password'] , 
				self::$_config['driver_options']
			); 
		} 
		catch(PDOException $e){
			 throw new SmartPHP_Db_Exception( $e->getMessage() );
		}
		return $connection;
    }
    
	/**
	 * _setDSN 
	 * 
	 * @access private
	 * @return string
	 */
	private static function _setDSN()
	{
		$dsn  = "mysql:host=" . self::$_config['host'] . ";";
		$dsn .= self::$_config['port'] ? "port=" . self::$_config['port'] . ";" : "";
		$dsn .= "dbname:".self::$_config['dbname'] ;
		return $dsn; 
	}
}

?>
